package com.gjy.concurrency.clazz;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.RecursiveTask;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-05-18 11:24:26
 */
public class RecursiveTaskTest {


    private static final class RTTask1 extends RecursiveTask<Integer> {

        private static final int THRESHOLD = 200;

        @Override
        protected Integer compute() {
            return null;
        }

        public static <T> List<List<T>> averageAssign(List<T> source, int n) {
            List<List<T>> result = new ArrayList<>();
            //(先计算出余数)
            int remainder = source.size() % n;
            //然后是商
            int number = source.size() / n;
            //偏移量
            int offset = 0;
            for (int i = 0; i < n; i++) {
                List<T> value;
                if (remainder > 0) {
                    value = source.subList(i * number + offset, (i + 1) * number + offset + 1);
                    remainder--;
                    offset++;
                } else {
                    value = source.subList(i * number + offset, (i + 1) * number + offset);
                }
                result.add(value);
            }
            return result;
        }
    }
}
